$(function(){
    var slideShowInterval,
	position,
	index = 0,
	length = $('div#slide-show > ul a').length,
	direction = -1;
    
    $('div#slide-show > ul a').each(function(i){
	$(this).click(function(){
	    $('div#slide-show > ul a.active').removeClass('active');
	    $(this).addClass('active');
	    
	    if(slideShowInterval || false){
		window.clearInterval(slideShowInterval);
	    }
	    
	    index = i;
	    position = -i * 985;
	    
	    $('div#slide-show > table').animate({
		'margin-left' : position+'px'
	    },300,function(){
		slideShowInterval = window.setInterval(function(){
		    $('div#slide-show > ul a').eq(index).trigger('click');
		    if(index == length - 1 || index == 0){
			direction *= -1;
		    }

		    index +=  direction;	
		}, 5000);
	    });
	    
	    $(this).trigger('blur');
	    return false;
	});
    });
    
    
    $('div#slide-show > ul a').eq(0).trigger('click');
});